package com.llh.uua.conf

import org.passay.MessageResolver
import org.passay.spring.SpringMessageResolver
import org.springframework.context.MessageSource
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean

/**
 * bean注册
 *
 * Created At 2021/3/16 21:28
 * @author llh
 */
@Configuration
class BeanRegister(private val messageSource: MessageSource) {


    /**
     * 配置 Passay 使用 Spring 的 MessageSource
     */
    @Bean
    fun messageResolver(): MessageResolver {
        return SpringMessageResolver(messageSource)
    }

    /**
     * 配置 Java Validation 使用国际化的消息资源
     */
    @Bean
    fun getValidator(): LocalValidatorFactoryBean {
        val bean = LocalValidatorFactoryBean()
        bean.setValidationMessageSource(messageSource)
        return bean
    }


}